package org.inspiration.dudu.message.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.inspiration.dudu.message.model.entity.SessionEntity;
import org.inspiration.dudu.message.model.vo.SessionVO;

import java.util.List;

@Mapper
public interface SessionMapper extends BaseMapper<SessionEntity> {
    @Select("select * from session where from_user_id = #{senderId} and to_user_id = #{receiverId}")
    SessionEntity find(Long senderId, Long receiverId);

    @Insert("insert into session(from_user_id, to_user_id) VALUES (#{fromUserId}, #{toUserId})")
    SessionEntity save(SessionEntity sessionEntity);

    @Update("update session set un_read_count = un_read_count + 1 where id = #{sessionId}")
    void increaseUnreadCount(Long sessionId);

    @Select("select * from session where from_user_id = #{fromUserId} limit #{offset}, #{pageSize}")
    List<SessionVO> getSessions(Long fromUserId, Integer offset, Integer pageSize);
}
